//控制巡逻组 传入组 
//修改为城市之间来回
//巡逻
params ["_group"];


private ["_end", "_target_pos"];
_group setBehaviour "SAFE";//"CARELESS";
_group setFormation "FILE";//"STAG COLUMN";//
_group setSpeedMode "LIMITED";

//所有载具到达目的地，则前往下一地点
_end = false;


while {!_end} do
{	
	private _unit = leader _group;

	if((isNull _unit) || {!alive _unit} || {isNull _group} || {count (units _group) == 0}) exitWith{};
	
	
	private _locs = [];
	private _pos = getPos _unit;
	_locs = nearestLocations [_pos, ["NameCityCapital","NameCity"], 8000, _pos];
	
	if(count _locs > 1) then
	{
		_locs deleteAt 0;
		_target_pos = getPos (selectRandom _locs);
		[_group,_target_pos] call fn_addWaypoint;
		
		if(Param_Debug == 1) then
		{
			private _marker = createMarker [format["marker_wp_%1", as_waypoint_cur], _target_pos];
			_marker setMarkerShape "ICON";
			_marker setMarkerColor "ColorRed";
			_marker setMarkerType "mil_arrow";
			_marker setMarkerText "巡逻";
			as_waypoint_cur = as_waypoint_cur + 1;
		};
	};
	waitUntil
	{
		Sleep 60;
		private _ret = true;
		{
			if(_x distance2D _target_pos > 500) exitWith
			{
				_ret = false;
			};
		}forEach (units _group);
		_ret
	};
	
	_group setBehaviour "SAFE";
};

